package od_2025A.one;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 题目：https://blog.csdn.net/qq_45776114/article/details/145728307
 */
public class Test06 {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int countA = Integer.parseInt(scanner.nextLine());
        int countB = Integer.parseInt(scanner.nextLine());
        String[] arrayA = scanner.nextLine().split(" ");
        String[] arrayB = scanner.nextLine().split(" ");
        scanner.close();

        //构建 arrayA 的 Map 集合
        Map<String, Integer> aMap = getMap(arrayA);
        Map<String, Integer> bMap = getMap(arrayB);

        int sum = 0;
        for (String value : aMap.keySet()) {
            Integer aCount = aMap.get(value);
            Integer bCount = bMap.get(value);
            if (Objects.isNull(bCount)) {
                continue;
            }
            sum += (aCount * bCount);
        }
        System.out.println(sum);
    }

    /**
     * 获取map
     * (元素-->元素出现的次数)
     *
     * @param array
     * @return
     */
    private static Map<String, Integer> getMap(String[] array) {
        Map<String, Integer> map = new HashMap<>();
        for (String str : array) {
            Integer strCount = map.get(str);
            if (Objects.isNull(strCount)) {
                strCount = 1;
            } else {
                strCount = strCount + 1;
            }
            map.put(str, strCount);
        }
        return map;
    }
}
